﻿/*
 * MiniFox.Portlet v3.0.0
 * Docs & License: http://hanko12.com
 * (c) 2019 漢口十二
 * mailto:8823428@qq.com
 */
+function (factory) {
    if (typeof define === 'function' && define.amd) {
        define(['jquery'], factory);
    }
    else {
        var $ = jQuery || require('jquery');
        factory($);
    }
}(function (jQuery) {
    "use strict";
    

    /********************* form begin *********************/

    (function ($) {

        var pluginName = "form";
        var defaults = {
            commitButton: '',
            url: window.location.href,
            httpmethod: "post",
            contentType: "application/json; charset=utf-8",
            showProcessing: true,
            requestModel: {},
            precommit: null,
            callback: null,
            onerror: null,
            rules: {},
            messages: {}
        };
        $.fn.form = function () {
            var method = arguments[0];
            var func = methods[method];
            var args = arguments;
            if (func && $.isFunction(func)) {
                args = Array.prototype.slice.call(args, 1);
            } else if ($.isPlainObject(method) || !method) {
                func = methods.init;
            } else {
                $.error('方法名 "' + method + '" 不存在。');
                return this;
            }
            return func.apply(this, args);
        };

        //初始化设置
        var createSetting = function (opt) {
            var plugin = $(this);
            var options = plugin.data(pluginName);

            if ($.type(options) == 'undefined') {
                options = $.extend({}, defaults, opt);
            } else {
                options = $.extend({}, options, opt);
            }

            plugin.data(pluginName, options);
            return options;
        };

        var methods = {
            init: function (opt) {
                return $(this).each(function () {

                    var $form = $(this);
                    if (opt) {
                        if (!opt.url) {
                            opt.url = $form.attr('action');
                        }
                        if (!opt.commitButton) {
                            opt.commitButton = $form.attr('commitButton');
                        }
                    }
                    var options = createSetting.apply($form, [opt]);

                    var fields = $form.find(":input").each(function () {
                        var id = $(this).attr("id");
                        var datatype = $(this).attr("data-type");
                        switch (datatype) {
                            case "lookup":
                                $(this).lookup();
                                break;
                            case "number":
                                $(this).wrap('<div class="input-group"></div>');
                                var $icon = $('<div class="input-group-addon">####</div>');
                                $(this).after($icon);
                                break;
                            case "date":
                                $(this).wrap('<div class="input-group"></div>');
                                var $icon = $('<div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div>');
                                $(this).after($icon);

                                $(this).datetimepicker({
                                    format: 'Y-m-d',
                                    lang: 'ch',
                                    timepicker: false,
                                    scrollInput: false,
                                    scrollMonth: false,
                                    scrollTime: false,
                                    closeOnDateSelect: true
                                });
                                $icon.click((function (input) { return function () { $(input).datetimepicker('show'); }; })(this));
                                break;
                            case "datetime":
                                $(this).wrap('<div class="input-group"></div>');
                                var $icon = $('<button onclick="return false" class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></button>');
                                $(this).after($icon);

                                $(this).datetimepicker({
                                    format: 'Y-m-d H:i',
                                    lang: 'ch',
                                    scrollInput: false,
                                    scrollMonth: false,
                                    scrollTime: false,
                                    closeOnDateSelect: true
                                });
                                $icon.click((function (input) { return function () { $(input).datetimepicker('show'); }; })(this));
                                break;
                            case "bool":
                                $(this).click(function () {
                                    $(this).val(this.checked);
                                });
                                break;
                            case "options":
                                if ($(this).is("select")) {
                                    $(this).selectmenu();
                                }

                                break;
                        }

                        var name = $(this).attr("name");
                        options.rules[name] = {};
                        options.messages[name] = {};
                        //for (var key in jQuery.validator.messages) {
                        //    var rule = jQuery.validator.rules[key];
                        //    var msg = $(this).attr(key) || $(this).attr("data-val-" + key);
                        //    if (msg) {
                        //        rules[name][key] = rule;
                        //        messages[name][key] = msg;
                        //    }
                        //}
                        var defaultVal = Boolean($(this).attr("data-val"));
                        var required = $(this).attr("required") || $(this).attr("data-val-required");
                        if (required) {
                            options.rules[name]["required"] = defaultVal;
                            options.messages[name]["required"] = required;
                        }
                    });

                    $(this).validate({
                        onkeyup: false,
                        onkeypress: false,
                        onkeydown: false,
                        onblur: false,
                        onfocusin: false,
                        onfocusout: false,
                        onfocus: false,
                        rules: options.rules,
                        messages: options.messages,
                        showErrors: function (errorMap, errorList) {
                            for (var i = 0; i < errorList.length; i++) {
                                //$(errorList[i].element).popover({ content: errorList[i].message, placement: 'right', trigger: 'manual', delay: { "show": 100, "hide": 100 } });
                                //$(errorList[i].element).popover('show');
                                $.alert(errorList[i].message, "警告", (function (ele) { return function () { $(ele).focus(); } })(errorList[i].element));
                                break;
                            }
                        }
                    });

                    if (options.commitButton) {
                        var btnSelector;
                        if (options.commitButton.indexOf('#') == 0)
                            btnSelector = options.commitButton;
                        else
                            btnSelector = '#' + options.commitButton;

                        $(btnSelector).click({ owner: this }, function (e) {
                            $(e.data.owner).form('commit');
                        });
                    }
                });
            },
            destroy: function (opt) {
                return $(this).each(function () {
                    var $this = $(this);
                    $this.removeData(pluginName);
                });
            },
            commit: function (opt) {

                return $(this).each(function () {
                    var $form = $(this);
                    var options = createSetting.apply($form, [opt]);

                    var request = options.requestModel;
                    var data = methods.getParameters.apply($form, [request.parameters]);
                    if (request.parameters != data)
                        request.parameters = data;
                    if (options.precommit && $.isFunction(options.precommit))
                        options.precommit.apply(this, [options]);

                    $.ajax({
                        url: options.url,
                        type: options.httpmethod,
                        data: JSON.stringify(request),
                        context: this,
                        cache: false,
                        contentType: options.contentType,
                        dataType: "json",
                        beforeSend: function (xhr) {

                            var isValid = $(this).valid();
                            if (isValid && options.showProcessing)
                                $(document.body).process('show');
                            return isValid;
                        },
                        success: (function (callback) {
                            return function (response) {
                                if (response && response.redirectUri) {
                                    window.location.href = response.redirectUri;
                                    return;
                                }
                                if (response.message) {
                                    $.alert(response.message, "", (function (that, c, r) {
                                        return function () {
                                            if (c && $.isFunction(c))
                                                c.apply(that, [r]);
                                        }
                                    })(this, callback, response));
                                } else {
                                    if (callback) callback.apply(this, [response]);
                                }
                            }
                        })(options.callback),
                        error: (function (onerror) {
                            return function (response) {
                                if (response && response.redirectUri) {
                                    window.location.href = response.redirectUri;
                                    return;
                                }
                                if (response.message) {
                                    $.alert(response.message, "错误", (function (that, c, r) {
                                        return function () {
                                            if (c && $.isFunction(c))
                                                c.apply(that, [r]);
                                        };
                                    })(this, onerror, response));
                                } else {
                                    if (onerror) onerror.apply(this, [response]);
                                }
                            }
                        })(options.onerror),
                        complete: function (xhr) {
                            if (options.showProcessing)
                                $(document.body).process('hide');
                        }
                    });
                });
            },
            reset: function (opt) {
                return $(this).each(function () {
                    var $form = $(this);
                    var options = createSetting.apply($form);
                    options = $.extend({}, options, opt);
                    $(this).find(':input[name]:enabled').each(function () {
                        var type = $(this).attr("type");
                        switch (type) {
                            case "checkbox":
                                $(this).prop("checked", false);
                                break;
                            case "lookup":

                                break;
                            default:
                                $(this).val('');
                                break;
                        }
                    });
                    //}
                });
            },
            getParameters: function (model) {
                model = model || {};

                var fields = $(this).find(":input[name]").each(function (n) {
                    var type = $(this).attr("type");
                    if (type == "button" || type == "submit")
                        return;

                    var datatype = $(this).attr("data-type");
                    var name = $(this).attr("name");
                    switch (datatype) {
                        case "bool":
                            if ($(this).is(":checkbox")) {
                                model[name] = this.checked;
                            }
                            else {
                                model[name] = $(this).val();
                            }
                            break;
                        case "array":
                            if ($(this).is(":checkbox")) {
                                model[name] = model[name] || [];
                                if ($(this).is(":checked"))
                                    model[name].push($(this).val());
                            }
                            else {
                                model[name] = $(this).val();
                            }
                            break;
                        case "lookup":
                            model[name] = $(this).val();
                            break;
                        case "options":
                            if ($(this).is(":radio")) {
                                if ($(this).is(":checked"))
                                    model[name] = $(this).val();
                            }
                            else {
                                model[name] = $(this).val();
                            }
                            break;
                        default:
                            model[name] = $(this).val();
                            break;
                    }
                });
                return model;
            }
        };



    })(jQuery);

    /********************* form end   *********************/

    /********************* icon list begin *********************/

    (function ($) {

        var pluginName = "iconlist";

        var icons = [
            "fa fa-address-book",
            "fa fa-address-book-o",
            "fa fa-address-card",
            "fa fa-address-card-o",
            "fa fa-adjust",
            "fa fa-american-sign-language-interpreting",
            "fa fa-anchor",
            "fa fa-archive",
            "fa fa-area-chart",
            "fa fa-arrows",
            "fa fa-arrows-h",
            "fa fa-arrows-v",
            "fa fa-asl-interpreting",
            "fa fa-assistive-listening-systems",
            "fa fa-asterisk",
            "fa fa-at",
            "fa fa-audio-description",
            "fa fa-automobile",
            "fa fa-balance-scale",
            "fa fa-ban",
            "fa fa-bank",
            "fa fa-bar-chart",
            "fa fa-bar-chart-o",
            "fa fa-barcode",
            "fa fa-bars",
            "fa fa-bath",
            "fa fa-bathtub",
            "fa fa-battery",
            "fa fa-battery-0",
            "fa fa-battery-1",
            "fa fa-battery-2",
            "fa fa-battery-3",
            "fa fa-battery-4",
            "fa fa-battery-empty",
            "fa fa-battery-full",
            "fa fa-battery-half",
            "fa fa-battery-quarter",
            "fa fa-battery-three-quarters",
            "fa fa-bed",
            "fa fa-beer",
            "fa fa-bell",
            "fa fa-bell-o",
            "fa fa-bell-slash",
            "fa fa-bell-slash-o",
            "fa fa-bicycle",
            "fa fa-binoculars",
            "fa fa-birthday-cake",
            "fa fa-blind",
            "fa fa-bluetooth",
            "fa fa-bluetooth-b",
            "fa fa-bolt",
            "fa fa-bomb",
            "fa fa-book",
            "fa fa-bookmark",
            "fa fa-bookmark-o",
            "fa fa-braille",
            "fa fa-briefcase",
            "fa fa-bug",
            "fa fa-building",
            "fa fa-building-o",
            "fa fa-bullhorn",
            "fa fa-bullseye",
            "fa fa-bus",
            "fa fa-cab",
            "fa fa-calculator",
            "fa fa-calendar",
            "fa fa-calendar-check-o",
            "fa fa-calendar-minus-o",
            "fa fa-calendar-o",
            "fa fa-calendar-plus-o",
            "fa fa-calendar-times-o",
            "fa fa-camera",
            "fa fa-camera-retro",
            "fa fa-car",
            "fa fa-caret-square-o-down",
            "fa fa-caret-square-o-left",
            "fa fa-caret-square-o-right",
            "fa fa-caret-square-o-up",
            "fa fa-cart-arrow-down",
            "fa fa-cart-plus",
            "fa fa-cc",
            "fa fa-certificate",
            "fa fa-check",
            "fa fa-check-circle",
            "fa fa-check-circle-o",
            "fa fa-check-square",
            "fa fa-check-square-o",
            "fa fa-child",
            "fa fa-circle",
            "fa fa-circle-o",
            "fa fa-circle-o-notch",
            "fa fa-circle-thin",
            "fa fa-clock-o",
            "fa fa-clone",
            "fa fa-close",
            "fa fa-cloud",
            "fa fa-cloud-download",
            "fa fa-cloud-upload",
            "fa fa-code",
            "fa fa-code-fork",
            "fa fa-coffee",
            "fa fa-cog",
            "fa fa-cogs",
            "fa fa-comment",
            "fa fa-comment-o",
            "fa fa-commenting",
            "fa fa-commenting-o",
            "fa fa-comments",
            "fa fa-comments-o",
            "fa fa-compass",
            "fa fa-copyright",
            "fa fa-creative-commons",
            "fa fa-credit-card",
            "fa fa-credit-card-alt",
            "fa fa-crop",
            "fa fa-crosshairs",
            "fa fa-cube",
            "fa fa-cubes",
            "fa fa-cutlery",
            "fa fa-dashboard",
            "fa fa-database",
            "fa fa-deaf",
            "fa fa-deafness",
            "fa fa-desktop",
            "fa fa-diamond",
            "fa fa-dot-circle-o",
            "fa fa-download",
            "fa fa-drivers-license",
            "fa fa-drivers-license-o",
            "fa fa-edit",
            "fa fa-ellipsis-h",
            "fa fa-ellipsis-v",
            "fa fa-envelope",
            "fa fa-envelope-o",
            "fa fa-envelope-open",
            "fa fa-envelope-open-o",
            "fa fa-envelope-square",
            "fa fa-eraser",
            "fa fa-exchange",
            "fa fa-exclamation",
            "fa fa-exclamation-circle",
            "fa fa-exclamation-triangle",
            "fa fa-external-link",
            "fa fa-external-link-square",
            "fa fa-eye",
            "fa fa-eye-slash",
            "fa fa-eyedropper",
            "fa fa-fax",
            "fa fa-feed",
            "fa fa-female",
            "fa fa-fighter-jet",
            "fa fa-file-archive-o",
            "fa fa-file-audio-o",
            "fa fa-file-code-o",
            "fa fa-file-excel-o",
            "fa fa-file-image-o",
            "fa fa-file-movie-o",
            "fa fa-file-pdf-o",
            "fa fa-file-photo-o",
            "fa fa-file-picture-o",
            "fa fa-file-powerpoint-o",
            "fa fa-file-sound-o",
            "fa fa-file-video-o",
            "fa fa-file-word-o",
            "fa fa-file-zip-o",
            "fa fa-film",
            "fa fa-filter",
            "fa fa-fire",
            "fa fa-fire-extinguisher",
            "fa fa-flag",
            "fa fa-flag-checkered",
            "fa fa-flag-o",
            "fa fa-flash",
            "fa fa-flask",
            "fa fa-folder",
            "fa fa-folder-o",
            "fa fa-folder-open",
            "fa fa-folder-open-o",
            "fa fa-frown-o",
            "fa fa-futbol-o",
            "fa fa-gamepad",
            "fa fa-gavel",
            "fa fa-gear",
            "fa fa-gears",
            "fa fa-gift",
            "fa fa-glass",
            "fa fa-globe",
            "fa fa-graduation-cap",
            "fa fa-group",
            "fa fa-hand-grab-o",
            "fa fa-hand-lizard-o",
            "fa fa-hand-paper-o",
            "fa fa-hand-peace-o",
            "fa fa-hand-pointer-o",
            "fa fa-hand-rock-o",
            "fa fa-hand-scissors-o",
            "fa fa-hand-spock-o",
            "fa fa-hand-stop-o",
            "fa fa-handshake-o",
            "fa fa-hard-of-hearing",
            "fa fa-hashtag",
            "fa fa-hdd-o",
            "fa fa-headphones",
            "fa fa-heart",
            "fa fa-heart-o",
            "fa fa-heartbeat",
            "fa fa-history",
            "fa fa-home",
            "fa fa-hotel",
            "fa fa-hourglass",
            "fa fa-hourglass-1",
            "fa fa-hourglass-2",
            "fa fa-hourglass-3",
            "fa fa-hourglass-end",
            "fa fa-hourglass-half",
            "fa fa-hourglass-o",
            "fa fa-hourglass-start",
            "fa fa-i-cursor",
            "fa fa-id-badge",
            "fa fa-id-card",
            "fa fa-id-card-o",
            "fa fa-image",
            "fa fa-inbox",
            "fa fa-industry",
            "fa fa-info",
            "fa fa-info-circle",
            "fa fa-institution",
            "fa fa-key",
            "fa fa-keyboard-o",
            "fa fa-language",
            "fa fa-laptop",
            "fa fa-leaf",
            "fa fa-legal",
            "fa fa-lemon-o",
            "fa fa-level-down",
            "fa fa-level-up",
            "fa fa-life-bouy",
            "fa fa-life-buoy",
            "fa fa-life-ring",
            "fa fa-life-saver",
            "fa fa-lightbulb-o",
            "fa fa-line-chart",
            "fa fa-location-arrow",
            "fa fa-lock",
            "fa fa-low-vision",
            "fa fa-magic",
            "fa fa-magnet",
            "fa fa-mail-forward",
            "fa fa-mail-reply",
            "fa fa-mail-reply-all",
            "fa fa-male",
            "fa fa-map",
            "fa fa-map-marker",
            "fa fa-map-o",
            "fa fa-map-pin",
            "fa fa-map-signs",
            "fa fa-meh-o",
            "fa fa-microchip",
            "fa fa-microphone",
            "fa fa-microphone-slash",
            "fa fa-minus",
            "fa fa-minus-circle",
            "fa fa-minus-square",
            "fa fa-minus-square-o",
            "fa fa-mobile",
            "fa fa-mobile-phone",
            "fa fa-money",
            "fa fa-moon-o",
            "fa fa-mortar-board",
            "fa fa-motorcycle",
            "fa fa-mouse-pointer",
            "fa fa-music",
            "fa fa-navicon",
            "fa fa-newspaper-o",
            "fa fa-object-group",
            "fa fa-object-ungroup",
            "fa fa-paint-brush",
            "fa fa-paper-plane",
            "fa fa-paper-plane-o",
            "fa fa-paw",
            "fa fa-pencil",
            "fa fa-pencil-square",
            "fa fa-pencil-square-o",
            "fa fa-percent",
            "fa fa-phone",
            "fa fa-phone-square",
            "fa fa-photo",
            "fa fa-picture-o",
            "fa fa-pie-chart",
            "fa fa-plane",
            "fa fa-plug",
            "fa fa-plus",
            "fa fa-plus-circle",
            "fa fa-plus-square",
            "fa fa-plus-square-o",
            "fa fa-podcast",
            "fa fa-power-off",
            "fa fa-print",
            "fa fa-puzzle-piece",
            "fa fa-qrcode",
            "fa fa-question",
            "fa fa-question-circle",
            "fa fa-question-circle-o",
            "fa fa-quote-left",
            "fa fa-quote-right",
            "fa fa-random",
            "fa fa-recycle",
            "fa fa-refresh",
            "fa fa-registered",
            "fa fa-remove",
            "fa fa-reorder",
            "fa fa-reply",
            "fa fa-reply-all",
            "fa fa-retweet",
            "fa fa-road",
            "fa fa-rocket",
            "fa fa-rss",
            "fa fa-rss-square",
            "fa fa-s15",
            "fa fa-search",
            "fa fa-search-minus",
            "fa fa-search-plus",
            "fa fa-send",
            "fa fa-send-o",
            "fa fa-server",
            "fa fa-share",
            "fa fa-share-alt",
            "fa fa-share-alt-square",
            "fa fa-share-square",
            "fa fa-share-square-o",
            "fa fa-shield",
            "fa fa-ship",
            "fa fa-shopping-bag",
            "fa fa-shopping-basket",
            "fa fa-shopping-cart",
            "fa fa-shower",
            "fa fa-sign-in",
            "fa fa-sign-language",
            "fa fa-sign-out",
            "fa fa-signal",
            "fa fa-signing",
            "fa fa-sitemap",
            "fa fa-sliders",
            "fa fa-smile-o",
            "fa fa-snowflake-o",
            "fa fa-soccer-ball-o",
            "fa fa-sort",
            "fa fa-sort-alpha-asc",
            "fa fa-sort-alpha-desc",
            "fa fa-sort-amount-asc",
            "fa fa-sort-amount-desc",
            "fa fa-sort-asc",
            "fa fa-sort-desc",
            "fa fa-sort-down",
            "fa fa-sort-numeric-asc",
            "fa fa-sort-numeric-desc",
            "fa fa-sort-up",
            "fa fa-space-shuttle",
            "fa fa-spinner",
            "fa fa-spoon",
            "fa fa-square",
            "fa fa-square-o",
            "fa fa-star",
            "fa fa-star-half",
            "fa fa-star-half-empty",
            "fa fa-star-half-full",
            "fa fa-star-half-o",
            "fa fa-star-o",
            "fa fa-sticky-note",
            "fa fa-sticky-note-o",
            "fa fa-street-view",
            "fa fa-suitcase",
            "fa fa-sun-o",
            "fa fa-support",
            "fa fa-tablet",
            "fa fa-tachometer",
            "fa fa-tag",
            "fa fa-tags",
            "fa fa-tasks",
            "fa fa-taxi",
            "fa fa-television",
            "fa fa-terminal",
            "fa fa-thermometer",
            "fa fa-thermometer-0",
            "fa fa-thermometer-1",
            "fa fa-thermometer-2",
            "fa fa-thermometer-3",
            "fa fa-thermometer-4",
            "fa fa-thermometer-empty",
            "fa fa-thermometer-full",
            "fa fa-thermometer-half",
            "fa fa-thermometer-quarter",
            "fa fa-thermometer-three-quarters",
            "fa fa-thumb-tack",
            "fa fa-thumbs-down",
            "fa fa-thumbs-o-down",
            "fa fa-thumbs-o-up",
            "fa fa-thumbs-up",
            "fa fa-ticket",
            "fa fa-times",
            "fa fa-times-circle",
            "fa fa-times-circle-o",
            "fa fa-times-rectangle",
            "fa fa-times-rectangle-o",
            "fa fa-tint",
            "fa fa-toggle-down",
            "fa fa-toggle-left",
            "fa fa-toggle-off",
            "fa fa-toggle-on",
            "fa fa-toggle-right",
            "fa fa-toggle-up",
            "fa fa-trademark",
            "fa fa-trash",
            "fa fa-trash-o",
            "fa fa-tree",
            "fa fa-trophy",
            "fa fa-truck",
            "fa fa-tty",
            "fa fa-tv",
            "fa fa-umbrella",
            "fa fa-universal-access",
            "fa fa-university",
            "fa fa-unlock",
            "fa fa-unlock-alt",
            "fa fa-unsorted",
            "fa fa-upload",
            "fa fa-user",
            "fa fa-user-circle",
            "fa fa-user-circle-o",
            "fa fa-user-o",
            "fa fa-user-plus",
            "fa fa-user-secret",
            "fa fa-user-times",
            "fa fa-users",
            "fa fa-vcard",
            "fa fa-vcard-o",
            "fa fa-video-camera",
            "fa fa-volume-control-phone",
            "fa fa-volume-down",
            "fa fa-volume-off",
            "fa fa-volume-up",
            "fa fa-warning",
            "fa fa-wheelchair",
            "fa fa-wheelchair-alt",
            "fa fa-wifi",
            "fa fa-window-close",
            "fa fa-window-close-o",
            "fa fa-window-maximize",
            "fa fa-window-minimize",
            "fa fa-window-restore",
            "fa fa-wrench",
            "fa fa-american-sign-language-interpreting",
            "fa fa-asl-interpreting",
            "fa fa-assistive-listening-systems",
            "fa fa-audio-description",
            "fa fa-blind",
            "fa fa-braille",
            "fa fa-cc",
            "fa fa-deaf",
            "fa fa-deafness",
            "fa fa-hard-of-hearing",
            "fa fa-low-vision",
            "fa fa-question-circle-o",
            "fa fa-sign-language",
            "fa fa-signing",
            "fa fa-tty",
            "fa fa-universal-access",
            "fa fa-volume-control-phone",
            "fa fa-wheelchair",
            "fa fa-wheelchair-alt",
            "fa fa-ambulance",
            "fa fa-automobile",
            "fa fa-bicycle",
            "fa fa-bus",
            "fa fa-cab",
            "fa fa-car",
            "fa fa-fighter-jet",
            "fa fa-motorcycle",
            "fa fa-plane",
            "fa fa-rocket",
            "fa fa-ship",
            "fa fa-space-shuttle",
            "fa fa-subway",
            "fa fa-taxi",
            "fa fa-train",
            "fa fa-truck",
            "fa fa-wheelchair",
            "fa fa-wheelchair-alt",
            "fa fa-file",
            "fa fa-file-o",
            "fa fa-file-text",
            "fa fa-file-text-o",
            "fa fa-align-center",
            "fa fa-align-justify",
            "fa fa-align-left",
            "fa fa-align-right",
            "fa fa-bold",
            "fa fa-chain",
            "fa fa-chain-broken",
            "fa fa-clipboard",
            "fa fa-columns",
            "fa fa-copy",
            "fa fa-cut",
            "fa fa-dedent",
            "fa fa-eraser",
            "fa fa-file",
            "fa fa-file-o",
            "fa fa-file-text",
            "fa fa-file-text-o",
            "fa fa-files-o",
            "fa fa-floppy-o",
            "fa fa-font",
            "fa fa-header",
            "fa fa-indent",
            "fa fa-italic",
            "fa fa-link",
            "fa fa-list",
            "fa fa-list-alt",
            "fa fa-list-ol",
            "fa fa-list-ul",
            "fa fa-outdent",
            "fa fa-paperclip",
            "fa fa-paragraph",
            "fa fa-paste",
            "fa fa-repeat",
            "fa fa-rotate-left",
            "fa fa-rotate-right",
            "fa fa-save",
            "fa fa-scissors",
            "fa fa-strikethrough",
            "fa fa-subscript",
            "fa fa-superscript",
            "fa fa-table",
            "fa fa-text-height",
            "fa fa-text-width",
            "fa fa-th",
            "fa fa-th-large",
            "fa fa-th-list",
            "fa fa-underline",
            "fa fa-undo",
            "fa fa-unlink"
        ];

        ;
        var defaults = {
            icons: icons,
            selecting: null,
            selectedIcon: ""
        };
        $.fn.iconlist = function () {
            var method = arguments[0];
            var func = methods[method];
            var args = arguments;
            if (func && $.isFunction(func)) {
                args = Array.prototype.slice.call(args, 1);
            } else if ($.isPlainObject(method) || !method) {
                func = methods.init;
            } else {
                $.error('方法名 "' + method + '" 不存在。');
                return this;
            }
            return func.apply(this, args);
        };

        //初始化设置
        var createSetting = function (opt) {
            var plugin = $(this);
            var options = plugin.data(pluginName);

            if ($.type(options) == 'undefined') {
                options = $.extend({}, defaults, opt);
            } else {
                options = $.extend({}, options, opt);
            }

            plugin.data(pluginName, options);
            return options;
        };

        var methods = {
            init: function (opt) {
                if (!$(this).hasClass("sys-icon-list")) {
                    $(this).addClass("sys-icon-list");
                }
                return $(this).each(function () {
                    var $plugin = $(this);
                    var options = createSetting.apply($plugin, [opt]);

                    $plugin.empty();
                    for (var i = 0; i < options.icons.length; i++) {
                        var icon = options.icons[i];
                        var li = $('<li></li>');
                        li.appendTo(this);
                        var span = $('<span></span>');
                        span.appendTo(li);
                        span.addClass(icon);
                        if (options.selectedIcon == icon)
                            li.addClass("selected");

                        li.click((function (opt) {
                            return function (e) {
                                $(this).addClass('selected').siblings().removeClass("selected");
                                var val = $(this).find(">span").attr("class");
                                opt.selectedIcon = val;
                                e = { data: val };
                                if (opt.selecting)
                                    opt.selecting.apply(this, [e]);
                            }
                        })(options));
                    }
                });
            },
            selectedIcon: function () {

                var plugin = this;
                var options = $(plugin).data(pluginName);
                var icon = options.selectedIcon;


                return icon;
            }
        }


    })(jQuery);

    /********************* icon list end  *********************/

    /********************* lookup begin *********************/

    (function ($) {

        var pluginName = "lookup";
        var defaults = {
            autoComplete: true,
            itemUrl: "",
            listupUrl: "", //自动补全查找数据的请求地址
            lookupUrl: "", //弹出窗口表格加载数据的请求地址
            accepting: null, //选择一项时执行的事件
            keyField: "",//主键字段
            textField: "",//显示文本字段
            sortField: "",//弹出列表的默认排序字段
            searchFields: null,//查找模糊匹配的字段(数组类型，如: ["Name","Description"])
            maxListItem: 10, //最大列表项
            //multipleSelect: false,//是否支持多选
            itemSelecting: null, //选中事件
            selectedItem: null, //当前选中项
            title: "查找",//弹出窗标题
            //rowdbClick: null 
        };
        $.fn.lookup = function () {
            var method = arguments[0];
            var func = methods[method];
            var args = arguments;
            if (func && $.isFunction(func)) {
                args = Array.prototype.slice.call(args, 1);
            } else if ($.isPlainObject(method) || !method) {
                func = methods.init;
            } else {
                $.error('方法名 "' + method + '" 不存在。');
                return this;
            }
            return func.apply(this, args);
        };

        //初始化设置
        var createSetting = function (opt) {
            opt = opt || {};
            opt.itemUrl = opt.itemUrl || $(this).attr("itemUrl");
            opt.listupUrl = opt.listupUrl || $(this).attr("listupUrl");
            opt.lookupUrl = opt.lookupUrl || $(this).attr("lookupUrl");
            opt.title = opt.title || $(this).attr("title");
            opt.keyField = opt.keyField || $(this).attr("keyField");
            opt.textField = opt.textField || $(this).attr("textField");
            opt.sortField = opt.sortField || $(this).attr("sortField");
            opt.searchFields = opt.searchFields || $(this).attr("searchFields").split(",");

            var plugin = $(this);
            var options = plugin.data(pluginName);
            if ($.type(options) == 'undefined') {
                options = $.extend({}, defaults, opt);
            } else {
                options = $.extend({}, options, opt);
            }
            plugin.data(pluginName, options);
            return options;
        };

        var methods = {
            init: function (opt) {
                return $(this).each(function () {
                    var $lookup = $(this);
                    var options = createSetting.apply($lookup, [opt]);
                    var id = $lookup.attr("id");
                    var name = $lookup.attr("name");

                    var $container = $('<div class="input-group"></div>');
                    $lookup.wrap($container);

                    if ($lookup.hasClass('input-sm')) {
                        $container.addClass('input-group-sm');
                    }

                    var $txt = $lookup.clone();
                    $txt.val("");
                    $lookup.after($txt);

                    $lookup.attr("type", "hidden");
                    $lookup.attr("data-toggle", "dropdown");

                    $txt.attr("type", "text");
                    $txt.removeAttr("data-toggle");
                    $txt.attr("id", id + "$" + options.textField);
                    $txt.attr("name", name + "_" + options.textField);

                    if (options.itemUrl && $lookup.val()) {
                        $.postsubmit({
                            url: options.itemUrl,
                            showProcessing: false,
                            postData: { id: $lookup.val() },
                            callback: function (item) {
                                if (item) {
                                    $txt.val(item[options.textField]);
                                }
                            }
                        });
                    }


                    var $bar = $('<a class="input-group-addon"><i class="glyphicon glyphicon-search"></i></a>');
                    $txt.after($bar);

                    var $list = $('<ul class="dropdown-menu"></ul>');
                    $bar.after($list);

                    var showSearchPanel = (function (opt) {
                        return function () {

                            var $dialog = $('<div></div>');
                            $dialog.appendTo(document.body);
                            var $searchrow = $('<div class="row"></div>');
                            $searchrow.appendTo($dialog);
                            var $searchcol = $('<div class="col-sm-12"></div>');
                            $searchcol.appendTo($searchrow);
                            var $gridrow = $('<div class="row"></div>');
                            $gridrow.appendTo($dialog);
                            var $gridcol = $('<div class="col-sm-12" style="height:400px;"></div>');
                            $gridcol.appendTo($gridrow);

                            $dialog.dialog({
                                title: opt.title,
                                autoOpen: true,
                                closeOnEscape: true,
                                show: "fade",
                                hide: "fade",
                                width: 600,
                                height: "auto",
                                resizable: false,
                                modal: true,
                                open: function (e, ui) {
                                    var $inputgroup = $('<div class="input-group input-group-sm"></div>');
                                    $inputgroup.appendTo($searchcol);
                                    var $keyword = $('<input type="text" class="form-control" placeholder="请在此输入关键字进行模糊查询"/>');
                                    $keyword.appendTo($inputgroup);
                                    $keyword.val($txt.val());

                                    $keyword.keyup(function () {
                                        $txt.val($(this).val());
                                    });

                                    var $btnGroup = $('<span class="input-group-btn"></span>');
                                    $btnGroup.appendTo($inputgroup);
                                    var $searchbtn = $('<button class="btn btn-primary"><i class="glyphicon glyphicon-search"></i> 查找</button>');
                                    $searchbtn.appendTo($btnGroup);


                                    //$gridrow.width($(this).innerWidth() - $searchrow.outerWidth());

                                    var $gridview = $('<div class="gridview"></div>');
                                    $gridview.appendTo($gridcol);

                                    $searchbtn.click({ ele: this }, function (e) {
                                        var dialog = e.data.ele;
                                        $gridview.gridview({
                                            dataloadUrl: opt.lookupUrl,
                                            showProcessing: false,
                                            autoLoad: true,
                                            sortField: opt.sortField,
                                            requestData: {
                                                parameters: {
                                                    keyword: $keyword.val(),
                                                    searchfields: opt.searchFields
                                                }
                                            },
                                            rowDbClick: function (e) {
                                                var row = e.data;
                                                $lookup.val(row[opt.keyField]);
                                                $txt.val(row[opt.textField]);
                                                $(dialog).dialog('close');
                                                opt.selectedItem = row;
                                                if (opt.itemSelecting && $.isFunction(opt.itemSelecting)) {
                                                    opt.itemSelecting.apply($lookup, [row]);
                                                }
                                            }
                                        });
                                    }).click();
                                },
                                beforeClose: function (e, ui) {

                                },
                                close: function (e, ui) {
                                    $(this).remove();
                                }
                            });
                        }
                    })(options);
                    $bar.click(showSearchPanel);

                    var task;
                    $txt.blur((function (opt) {
                        return function () {
                            if (task)
                                clearTimeout(task);
                            var val = $(this).val();
                            if ($.trim(val) == "") {
                                $lookup.val("");
                            }
                        };
                    })(options));

                    $txt.keyup((function (opt) {
                        return function () {
                            if (task)
                                clearTimeout(task);
                            $lookup.val("");
                            if ($.trim($(this).val())) {
                                var val = $(this).val();
                                task = setTimeout(function () {

                                    $.postsubmit({
                                        url: opt.listupUrl,
                                        showProcessing: false,
                                        postData: { keyword: val, searchfields: opt.searchFields },
                                        callback: function (response) {
                                            if (response && $.isArray(response.Result)) {
                                                var data = response.Result;
                                                $list.empty();
                                                if (response.Result.length > 0) {

                                                    for (var i = 0; i < data.length; i++) {
                                                        var item = data[i];
                                                        var $li = $('<li></li>');
                                                        $li.appendTo($list);
                                                        var $a = $('<a class="item" href="#">' + item[opt.textField] + '</a>');
                                                        $a.appendTo($li);

                                                        $a.click(item, function (e) {
                                                            $lookup.val(e.data[opt.keyField]);
                                                            $txt.val(e.data[opt.textField]);

                                                            opt.selectedItem = e.data;
                                                            if (opt.itemSelecting && $.isFunction(opt.itemSelecting)) {
                                                                opt.itemSelecting(e.data);
                                                            }
                                                        });

                                                        if ($.trim($txt.val()) == item[opt.textField]) {
                                                            $lookup.val(item[opt.keyField]);
                                                            opt.selectedItem = e.data;
                                                        }
                                                        else {
                                                            $lookup.val("");
                                                            opt.selectedItem = null;
                                                        }
                                                    }

                                                    if (response.RowCount > response.Result.length) {
                                                        var $more = $('<li></li>');
                                                        $more.appendTo($list);

                                                        var $more_a = $('<a href="#">查找更多</a>');
                                                        $more_a.appendTo($more);
                                                        $more_a.click(showSearchPanel);
                                                    }

                                                    if ($list.is(':hidden')) {
                                                        $list.dropdown('toggle');
                                                    }
                                                }
                                            }
                                        }
                                    });
                                }, 600);
                            }
                            else {
                                if ($list.is(':visible')) {
                                    $list.dropdown('toggle');
                                    $list.empty();
                                }
                            }
                        }
                    })(options));

                });
            },
            destroy: function (opt) {
                return $(this).each(function () {
                    var $this = $(this);
                    $this.removeData(pluginName);
                });
            },

            selectedItem: function () {

                var plugin = this;
                var options = $(plugin).data(pluginName);
                var item = options.selectedItem;


                return item;
            }
        }
    })(jQuery);

    /********************* lookup end  *********************/

    /********************* gridview begin *********************/
    (function ($) {
        var pluginName = "gridview";
        //属性
        var defaults = {
            dataloadUrl: "",    //加载数据时的请求地址
            context: "",        //上下文
            columns: null,      //列名 {"column1" : {"SortField": "", "DisplayName":"", "DataType":""}, "column2" : {...} , "column3" : {...} , "column4" : {...} }
            pageSize: 20,       //页记录数
            sortField: "",
            sortDesc: true,
            resizable: true,
            primaryKey: null,
            selectable: false,  //是否可选择
            editInline: false,
            checkBoxName: "",
            rowChecked: null,
            rowCreating: null,
            rowRender: null,
            rowDelete: null,
            rowEdit: null,
            rowSelected: null,  //行选择事件（selectable为true时生效）
            rowClick: null,     //行点击事件
            rowDbClick: null,   //行双击事件
            rowHover: null,     //鼠标事件
            rowUnHover: null,   //鼠标离开事件
            cellClick: null,
            operations: {},     //字段点击事件{"字段名":function(r){}}
            requestData: {},    //请求的表单数据
            autoLoad: false,    //自动加载数据
            showProcessing: true,
            showPageInfo: true,
            showPagePanel: true,    //显示页操作面板
            dataModel: { columns: [], rows: [] },    //数据模型  { columns:[], rows:[] }
            rowCount: 0,
            pageCount: 0,
            selectedRow: null,
            checkedRows: null
        };
        $.fn.gridview = function () {
            var method = arguments[0];
            var func = methods[method];
            var args = arguments;
            if (func && $.isFunction(func)) {
                args = Array.prototype.slice.call(args, 1);
            } else if ($.isPlainObject(method) || !method) {
                func = methods.init;
            } else {
                $.error('方法名 "' + method + '" 不存在。');
                return this;
            }
            return func.apply(this, args);
        };

        //初始化设置
        var createSetting = function (opt) {
            var plugin = $(this);
            var options = plugin.data(pluginName);
            if ($.type(options) == 'undefined') {
                options = $.extend({}, defaults, opt);
            } else {
                options = $.extend({}, options, opt);
            }
            plugin.data(pluginName, options);
            return options;
        };
        //方法
        var methods = {
            init: function (opt) {
                return $(this).each(function () {

                    var $gridview = $(this);
                    var options = createSetting.apply($gridview, [opt]);
                    options.pageIndex = 1;
                    //绘制 begin

                    $gridview.empty();
                    if (!$gridview.hasClass("gridview"))
                        $gridview.addClass("gridview");

                    var $head = $('<div class="gridview-head"></div>');
                    $head.appendTo($gridview);
                    var $body = $('<div class="gridview-body"></div>');
                    $body.appendTo($gridview);
                    var $foot = $('<div class="gridview-foot"></div>');
                    $foot.appendTo($gridview);

                    var $head_columns = $('<div class="gridview-head-columns"></div>');
                    $head_columns.appendTo($head);
                    var $head_op = $('<div class="gridview-head-op pull-right"></div>');
                    $head_op.appendTo($head);

                    var $refresh = $('<a href="#"><i class="glyphicon glyphicon-refresh"></i></a>');
                    $refresh.click((function (gridview) {
                        return function () {
                            loadData.apply(gridview, [options]);
                        }
                    })($gridview));
                    $refresh.appendTo($head_op);

                    //滚动同步 begin
                    var h_scrolling = (function (gridview) {
                        return function () {
                            var headColumns = $(gridview).find('.gridview-head .gridview-head-columns');
                            headColumns.scrollLeft($(this).scrollLeft());
                            var footSummary = $(gridview).find('.gridview-foot .gridview-foot-summary');
                            footSummary.scrollLeft($(this).scrollLeft());
                        };
                    })($gridview);
                    $body.scroll(h_scrolling);
                    //滚动同步 end


                    //创建表头
                    var $head_table = $('<table class="table"></table>');
                    $head_table.appendTo($head_columns);
                    //创建表体
                    var $body_table = $('<table class="table"></table>');
                    $body_table.appendTo($body);

                    var columnCreated = createHeadColumn.apply($gridview, [options]);
                    $(window).resize(MiniFox.debounce((function (gridview) {
                        return function () {
                            var parent_h = $(gridview).parent().innerHeight();
                            $(gridview).height(parent_h);
                            var grid_h = $(gridview).innerHeight();
                            var head_h = $(gridview).find(".gridview-head").outerHeight();
                            if (head_h < 32) head_h = 32;
                            var foot_h = $(gridview).find(".gridview-foot").outerHeight();
                            if (foot_h < 32) foot_h = 32;
                            if (!options.showPagePanel) foot_h = 0;
                            var main_h = grid_h - head_h - foot_h;
                            $(gridview).find(".gridview-body").height(main_h);
                        }
                    })(this)));
                    //绘制 end

                    if (options.autoLoad) {
                        loadData.apply($gridview, [options]);
                    } else {
                        renderData.apply($gridview, [options]);
                    }

                    $(window).resize();
                });
            },
            destroy: function (opt) {
                return $(this).each(function () {
                    var $this = $(this);
                    $this.removeData(pluginName);
                });
            },
            selectedRow: function (row) {

                var plugin = this;
                var options = $(plugin).data(pluginName);
                if (row) {
                    //刷新grid
                    var pkv;
                    if (options.primaryKey) {
                        if ($.isArray(options.primaryKey)) {
                            var pkVals = [];
                            $.each(options.primaryKey, function (i, pk) {
                                pkVals.push(row[pk]);
                            });
                            pkv = pkVals.join("-");
                        }
                        else {
                            pkv = row[options.primaryKey];
                        }

                        var $tr = $(plugin).find(".gridview-body-tr[data-pk='" + pkv + "']");
                        $tr.click();
                    }
                }
                return options.selectedRow;
            },
            checkedRows: function (rows) {
                var plugin = this;
                var options = $(plugin).data(pluginName);
                if (rows) {
                    $(plugin).find(".gridview-body-tr :checkbox[name='" + options.checkBoxName + "']").prop("checked", false);

                    rows = $.isArray(rows) ? rows : [rows];
                    if (rows.length > 0) {
                        //刷新grid
                        $.each(rows, function (i, row) {
                            var pkv;
                            if (options.primaryKey) {
                                if ($.isArray(options.primaryKey)) {
                                    var pkVals = [];
                                    $.each(options.primaryKey, function (i, pk) {
                                        pkVals.push(row[pk]);
                                    });
                                    pkv = pkVals.join("-");
                                }
                                else {
                                    pkv = row[options.primaryKey];
                                }

                                var $chk = $(plugin).find(".gridview-body-tr[data-pk='" + pkv + "'] :checkbox[name='" + options.checkBoxName + "']");
                                $chk.trigger("rowChecking", true);;
                            }
                        })
                    }
                    else {
                        options.checkedRows = rows;
                    }
                }
                return options.checkedRows;
            }
        };
        //创建表头列
        var createHeadColumn = function (opt) {
            var columns = opt.columns;
            if (!columns)
                return false;

            var $head_table = $(this).find(".gridview-head .gridview-head-columns > table");
            $head_table.empty();

            var $body_table = $(this).find(".gridview-body > table");

            var $thead = $('<thead></thead>').appendTo($head_table);
            //表头行
            var $head_tr = $('<tr></tr>');
            $head_tr.appendTo($thead);

            try {
                /****************** head ******************/
                //创建列头
                if (opt.checkBoxName) { // 显示checkbox
                    var $head_th = $('<th></th>');
                    $head_th.appendTo($head_tr);
                    var $head_column = $('<div class="gridview-head-column"></div>');
                    $head_column.appendTo($head_th);
                    var $select_all = $('<input type="checkbox" />');
                    $select_all.appendTo($head_column);
                    $head_column.addClass("chk");
                    //$head_column.width(20);
                    //selectall event
                    $select_all.click((function (body_table) {

                        return function () {
                            var i = $(this).parent().parent().index();

                            body_table.find("tr").find("td:eq(" + i + ") :checkbox").trigger("rowChecking", [this.checked]);
                        }
                    })($body_table));
                }

                for (var c = 0; c < columns.length; c++) {

                    var column = columns[c];

                    var $head_th = $('<th></th>');
                    $head_th.appendTo($head_tr);
                    var $head_column = $('<div class="gridview-head-column" name="' + column.name + '"></div>');
                    $head_column.appendTo($head_th);
                    if (column.width && typeof column.width == 'number') {
                        
                        $head_column.outerWidth(column.width);
                    }
                    else {

                        if (column.dataType == "MultilineText")
                            $head_column.outerWidth(200);
                        else if (column.dataType == "datetime")
                            $head_column.outerWidth(150);
                        else
                            $head_column.outerWidth(100);
                    }
                    var $head_column_txt = $('<span class="gridview-head-column-txt"></span>');
                    $head_column_txt.appendTo($head_column);
                    $head_column_txt.text(column.displayName);
                    $head_column_txt.width($head_column.innerWidth());


                    if (column.sortField) {
                        var sortField = column.sortField;
                        var sortDesc = Boolean(column.sortDesc);

                        //sort arrow
                        var icon_sort = sortDesc ? "glyphicon-sort-by-alphabet-alt" : "glyphicon-sort-by-alphabet";
                        var $head_column_sort = $('<a href="#" class="glyphicon pull-right"></a>');
                        $head_column_sort.appendTo($head_column);
                        $head_column_sort.addClass(icon_sort);

                        var sort_w = $head_column_sort.outerWidth();
                        if (sort_w <= 0) sort_w = 20;
                        $head_column_txt.width($head_column.innerWidth() - sort_w - 14);
                        //console.log($(this).attr("id") + "sort_w:" + sort_w);


                        $head_column_sort.click({ sortField: sortField, sortDesc: sortDesc }, (function (gridview) {
                            return function (e) {
                                opt.sortField = e.data.sortField;
                                opt.sortDesc = !opt.sortDesc;
                                var icon = opt.sortDesc ? "glyphicon-sort-by-alphabet-alt" : "glyphicon-sort-by-alphabet";
                                if ($(this).hasClass("glyphicon-sort-by-alphabet")) {
                                    $(this).removeClass("glyphicon-sort-by-alphabet");
                                }
                                else if ($(this).hasClass("glyphicon-sort-by-alphabet-alt")) {
                                    $(this).removeClass("glyphicon-sort-by-alphabet-alt");
                                }
                                $(this).addClass(icon);
                                loadData.apply(gridview, [opt]);
                            }
                        })($(this)));

                        $head_column_txt.addClass("link");
                    }

                    if (opt.resizable) {

                        $head_column.resizable({
                            handles: "e",
                            resize: (function (body_table) {
                                return function () {
                                    var i = $(this).parent().index();
                                    var w = $(this).width();
                                    body_table.find("tr").find("td:eq(" + i + ") .gridview-body-cell").width(w);

                                    var gap = $(this).find(".pull-right").outerWidth();
                                    $(this).find(".gridview-head-column-txt").width($(this).innerWidth() - gap - 10);

                                }
                            })($body_table)
                        });
                    }

                }

                var $head_whitespace = $("<th></th>");
                $head_whitespace.appendTo($head_tr);

                /****************** head end ******************/
                return true;
            }
            catch (e) {

                return false;
            }
        };

        var renderData = function (opt) {
            var $head_table = $(this).find(".gridview-head .gridview-head-columns > table");
            var $body_table = $(this).find(".gridview-body > table");

            var columnCreated = $head_table.find(".gridview-head-column").size() > 0;
            if (!columnCreated) {
                columnCreated = createHeadColumn.apply(this, [opt]);
            }
            createFootPage.apply(this, [opt]);

            $body_table.empty();
            var $tbody = $('<tbody></tbody>').appendTo($body_table);

            if (columnCreated) {

                /****************** body ******************/
                for (var r = 0; r < opt.dataModel.rows.length; r++) {

                    var row = opt.dataModel.rows[r].dataItem;
                    //创建行
                    var $body_tr = $('<tr class="gridview-body-tr"></tr>');
                    $body_tr.appendTo($tbody);
                    if (opt.primaryKey) {
                        if ($.isArray(opt.primaryKey)) {
                            var pkVals = [];
                            $.each(opt.primaryKey, function (i, pk) {
                                pkVals.push(row[pk]);
                            });
                            $body_tr.attr("data-pk", pkVals.join("-"));
                        }
                        else {
                            $body_tr.attr("data-pk", row[opt.primaryKey]);
                        }
                    }
                    var $chk;
                    if (opt.checkBoxName) { // 显示checkbox
                        var $body_td = $('<td></td>');
                        $body_td.appendTo($body_tr);
                        var $body_cell = $('<div class="gridview-body-cell"></div>');
                        $body_cell.appendTo($body_td);
                        $body_cell.addClass("chk");

                        $chk = $('<input type="checkbox" name="' + opt.checkBoxName + '"/>');
                        $chk.appendTo($body_cell);
                        var exist = opt.checkedRows && opt.checkedRows.any(function (item) {
                            if ($.isArray(opt.primaryKey)) {
                                var equal = true;

                                $.each(opt.primaryKey, function (i, pk) {
                                    if (typeof pk != 'string') {
                                        equal = false;
                                        return false;
                                    }
                                    equal &= item[pk] === r[pk];
                                });
                                return equal;
                            }
                            else {
                                return item[opt.primaryKey] === r[opt.primaryKey];
                            }
                        });
                        if (exist)
                            $chk.prop("checked", true);
                    }

                    if (opt.rowCreating) {

                        var rowcreating = opt.rowCreating;
                        var edata = { data: row, checked: false };

                        if (rowcreating && $.isFunction(rowcreating)) rowcreating.apply($body_tr, [edata]);
                        if ($chk) $chk.prop("checked", edata.checked);
                    }

                    for (var c = 0; c < opt.columns.length; c++) {

                        var column = opt.columns[c];

                        //定义字段对象
                        var field = {
                            row: row,
                            name: column.name,
                            column: column,
                            getValue: function () {
                                var key_arr = this.name.split('.');
                                var i = 0;
                                var val = this.row;
                                do {
                                    var key = key_arr[i++];
                                    val = (val[key] == null ? "" : val[key]);
                                    if (!val)
                                        break;
                                } while (i < key_arr.length);

                                if ($.type(val) == "string") {
                                    if (val.isDate()) {
                                        val = val.toDate();
                                        var format = column.dataFormat;
                                        if (this.column.dataType == "date") {
                                            format = format || "yyyy-MM-dd";
                                        }
                                        else {
                                            format = format || "yyyy-MM-dd HH:mm:ss";
                                        }
                                        val = val.pattern(format);
                                    }
                                }
                                if ($.type(val) == "object") { // Lookup 类型 或者 OptionSet 类型显示 Text属性
                                    if (this.column && this.column.targetField) {
                                        val = val[this.column.targetField];
                                    }
                                    else {
                                        if (val.text)
                                            val = val.text;
                                        else
                                            val = "";
                                    }
                                }
                                return val;
                            },
                            setValue: function (val) {
                                this.row[this.name] = val;
                            }
                        };

                        var $body_td = $('<td class="gridview-body-td"></td>');
                        $body_td.appendTo($body_tr);
                        var $body_cell = $('<div class="gridview-body-cell" name="' + field.name + '"></div>');
                        $body_cell.appendTo($body_td);

                        var idx = $body_tr.find("td").index($body_td);
                        $body_cell.width($head_table.find("tr").find("th:eq(" + idx + ") div[name]").width());

                        var $body_cell_txt = $('<span class="gridview-body-cell-txt"></span>');
                        $body_cell_txt.appendTo($body_cell);
                        var val = field.getValue();
                        val = (val == null || $.type(val) == "undefined") ? "" : val;
                        if (field.column.dataType == "icon") {
                            $('<i class="' + val + '"></i>').appendTo($body_cell_txt);
                        }
                        else {
                            $body_cell_txt.text(val);
                            if (field.column.dataType == "number") {
                                $body_cell_txt.css("text-align", "right");
                            }
                            else {
                                $body_cell_txt.attr("title", val);
                            }
                        }

                        if (opt.operations[field.name]) {
                            var oprt = opt.operations[field.name];
                            var cellclick = (function (o) {
                                return function (e) {
                                    o(e);
                                    return false;
                                }
                            })(oprt);
                            $body_cell_txt.addClass("link");
                            $body_cell_txt.click(field, cellclick);
                        }
                    }

                    var $body_whitespace = $("<td></td>");
                    $body_whitespace.appendTo($body_tr);

                    if ($chk) {
                        var rowChecked = opt.rowChecked;
                        var ck_checking = (function (body_table, head_table, r) {
                            return function (e, checked) {
                                $(this).prop("checked", checked)
                                var i = $(this).parent().parent().index();
                                var selectAll = body_table.find("tr").find(".chk:eq(" + i + ") :checked").length == opt.dataModel.rows.length;
                                head_table.find(".chk:eq(" + i + ") :checkbox").prop("checked", selectAll);
                                opt.checkedRows = opt.checkedRows || [];
                                if (this.checked) {
                                    opt.checkedRows.push(r);
                                }
                                else {
                                    opt.checkedRows.remove(function (item) {
                                        if ($.isArray(opt.primaryKey)) {
                                            var equal = true;

                                            $.each(opt.primaryKey, function (i, pk) {
                                                if (typeof pk != 'string') {
                                                    equal = false;
                                                    return false;
                                                }
                                                equal &= item[pk] === r[pk];
                                            });
                                            return equal;
                                        }
                                        else {
                                            return item[opt.primaryKey] === r[opt.primaryKey];
                                        }
                                    });
                                }
                                if (rowChecked) rowChecked.apply(this, [{ checked: this.checked, row: r }]);
                            }
                        })($body_table, $head_table, row);
                        $chk.bind("rowChecking", ck_checking);
                        $chk.click(function () {
                            $(this).trigger("rowChecking", [this.checked]);
                        });
                    }

                    var rowclick = opt.rowClick;
                    var rowselected = opt.rowSelected;
                    $body_tr.click(row, function (e) {
                        if ($chk) {
                            e.checked = $chk.prop("checked");
                        }
                        if (opt.selectable) {
                            if (!$(this).hasClass("gridview-body-tr-selected")) {
                                $(this).addClass("gridview-body-tr-selected").siblings().removeClass("gridview-body-tr-selected");
                                opt.selectedRow = e.data;
                                if (rowselected) rowselected.apply(this, [e]);
                            }
                        }
                        if (rowclick) rowclick.apply(this, [e]);


                        if ($chk) {
                            $chk.prop("checked", e.checked)
                        }
                    });

                    var rowdbclick = opt.rowDbClick;
                    $body_tr.dblclick(row, function (e) {
                        if ($chk) {
                            e.checked = $chk.prop("checked");
                        }
                        if (rowdbclick) rowdbclick.apply(this, [e]);
                    });

                    if (opt.rowEdit && $.isFunction(opt.rowEdit)) {
                        var $edi_btn = $('<a href="#" class="btn-edi pull-right"><i class="glyphicon glyphicon-edit"></i></a>');
                        $edi_btn.appendTo($body_whitespace);

                        $edi_btn.click(row, opt.rowEdit);
                    }
                    if (opt.rowDelete && $.isFunction(opt.rowDelete)) {
                        var $del_btn = $('<a href="#" class="btn-del pull-right"><i class="glyphicon glyphicon-trash"></i></a>');
                        $del_btn.appendTo($body_whitespace);

                        $del_btn.click(row, opt.rowDelete);
                    }

                    if (opt.rowHover && $.isFunction(opt.rowHover)) {
                        $body_tr.hover(row, opt.rowHover);
                    }


                    if (opt.rowRender) {

                        var rowrender = opt.rowRender;
                        var edata = { data: row, checked: false };

                        if (rowrender && $.isFunction(rowrender)) rowrender.apply($body_tr, [edata]);
                    }

                }
                if (opt.checkBoxName) {
                    $head_table.find(".chk :checkbox").each(function () {
                        var i = $(this).parent().parent().index();

                        var selectAll = opt.dataModel.rows.length > 0 && $body_table.find("tr").find("td:eq(" + i + ") :checked").length == opt.dataModel.rows.length;
                        $(this).prop("checked", selectAll);
                    });
                }

                $(window).resize();
                /****************** body end ******************/
            }

        };

        var createFootPage = function (opt) {
            var $foot = $(this).find(".gridview-foot");
            $foot.empty();
            var dataModel = opt.dataModel;

            //创建汇总面板
            if (opt.summary) {
                var $foot_summary = $('<div class="gridview-foot-summary"></div>');
                $foot_summary.appendTo($foot);
            }
            //创建分页面板
            var $foot_page = $('<div class="gridview-foot-page"></div>');
            $foot_page.appendTo($foot);
            /****************** page ******************/
            if (dataModel && dataModel.rows && dataModel.rows.length > 0) {

                if (opt.showPagePanel) {
                    var isF = (opt.pageIndex <= 1);
                    var isL = (opt.pageIndex >= opt.pageCount);

                    var $page_first = $('<a href="#"><i class="glyphicon glyphicon-step-backward"></i></a>');
                    $page_first.appendTo($foot_page);
                    var $page_prev = $('<a href="#"><i class="glyphicon glyphicon-triangle-left"></i></a>');
                    $page_prev.appendTo($foot_page);

                    if (isF) {
                        $page_first.addClass("disable");
                        $page_prev.addClass("disable");
                    }
                    else {
                        $page_first.click((function (gridview) {
                            return function (e) {
                                if (opt.pageIndex <= 1)
                                    return;
                                opt.pageIndex = 1;
                                loadData.apply(gridview, [opt]);
                            }
                        })($(this)));

                        $page_prev.click((function (gridview) {
                            return function (e) {
                                if (opt.pageIndex <= 1)
                                    return;
                                opt.pageIndex--;
                                loadData.apply(gridview, [opt]);
                            }
                        })($(this)));
                    }

                    var $page_index = $('<span class="pindex" >' + opt.pageIndex + '</span>');
                    $page_index.appendTo($foot_page);

                    var $page_next = $('<a href="#"><i class="glyphicon glyphicon-triangle-right"></i></a>');
                    $page_next.appendTo($foot_page);
                    var $page_last = $('<a href="#"><i class="glyphicon glyphicon-step-forward"></i></a>');
                    $page_last.appendTo($foot_page);

                    if (isL) {
                        $page_next.addClass("disable");
                        $page_last.addClass("disable");
                    }
                    else {
                        $page_next.click((function (gridview) {
                            return function (e) {
                                if (opt.pageIndex >= opt.pageCount)
                                    return;
                                opt.pageIndex++;
                                loadData.apply(gridview, [opt]);
                            }
                        })($(this)));

                        $page_last.click((function (gridview) {
                            return function (e) {
                                if (opt.pageIndex >= opt.pageCount)
                                    return;
                                opt.pageIndex = opt.pageCount;
                                loadData.apply(gridview, [opt]);
                            }
                        })($(this)));
                    }

                    if (opt.showPageInfo) {
                        var $page_info = $("<span> 总共 " + opt.pageCount + " 页/ " + opt.rowCount + " 条记录</span>");
                        $page_info.appendTo($foot_page);
                    }
                }
                else {
                    $foot.hide();
                }
            }
            else {

                var p = $("<span> 查找不到符合条件的记录。 </span>");
                p.appendTo($foot_page);
            }

            /****************** page end ******************/

        }

        var loadData = function (opt) {

            var pageRequest = $.extend({}, opt.requestData, {
                pageIndex: opt.pageIndex,
                pageSize: (opt.pageSize && opt.pageSize > 0) ? opt.pageSize : 10,
                sortField: opt.sortField,
                sortDesc: opt.sortDesc
            });

            if ($.trim(opt.dataloadUrl) == "")
                return;
            $.ajax({
                url: opt.dataloadUrl,
                type: "post",
                data: JSON.stringify(pageRequest),
                context: this,
                cache: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: function () { if (opt.showProcessing) $(document.body).process('show'); },
                success: function (response) {
                    if (!response.success) {
                        if (response.redirectUri)
                            window.location.href = response.redirectUri;
                        if (response.message)
                            $.alert(response.message);
                        return;
                    }
                    else if (response.data) {
                        opt.dataModel = response.data.result;
                        opt.rowCount = response.data.rowCount;
                        opt.pageCount = response.data.pageCount;
                        if (!opt.columns || opt.columns.length <= 0) {
                            opt.columns = opt.dataModel.columns;
                        }
                        renderData.apply(this, [opt]);
                    }
                },
                error: function (xhr) {
                    var response = $.parseJSON(xhr.responseText);
                    if (response && response.message)
                        $.alert(response.message);
                },
                complete: function (xhr) {
                    if (opt.showProcessing) $(document.body).process('hide');
                }
            });
        };

    })(jQuery);

    /********************* gridview end *********************/

    /********************* treeview begin *********************/
    (function ($) {

        var pluginName = "treeview";
        var defaults = {
            dataloadUrl: "", //加载数据时的请求地址
            selectable: true, //是否可选择
            requestData: null, //请求的表单数据
            treeModel: {}, //数据模型
            uniqueField: "", //主键字段
            joinField: "", //自联字段 
            levelField: "", //层级字段
            displayField: "", //显示字段
            childrenField: "", //子集字段
            iconField: "",
            selectedItem: null,
            nodeExpanded: null,// function(e){}
            nodeCollapsed: null,// function(e){}
            nodeReorder: null,
            nodeRender: null, //节点呈现时触发
            asyncLoad: false,
            autoExpand: false
        };

        //初始化设置
        var createSetting = function (opt) {
            var plugin = $(this);
            var options = plugin.data(pluginName);
            if ($.type(options) == 'undefined') {
                options = $.extend({}, defaults, opt);
            } else {
                options = $.extend({}, options, opt);
            }
            plugin.data(pluginName, options);
            return options;
        };

        $.fn.treeview = function () {
            var method = arguments[0];
            var func = methods[method];
            var args = arguments;
            if (func) {
                args = Array.prototype.slice.call(args, 1);
            } else if (typeof (method) == 'object' || !method) {
                func = methods.init;
            } else {
                $.error('方法 ' + method + ' 不存在');
                return this;
            }
            return func.apply(this, args);
        };


        var recursion = function (item) {
            var plugin = this;
            var options = $(plugin).data(pluginName);
            var nodeData = item.data,
                $parentNode = $(item.element),
                parentNodeData = item.parentData;

            if (!nodeData)
                return;

            if ($parentNode == null || $parentNode.length <= 0)
                $parentNode = $(plugin);
            var $node = methods.createNode.apply(plugin, [item]);

            var children = nodeData[options.childrenField];
            if (children && children.length > 0) {
                for (var i = 0; i < children.length; i++) {
                    var childNode = children[i];
                    recursion.apply(plugin, [{ data: childNode, element: $node.get(0), parentData: nodeData }]);
                }
            }
        };

        var nodeToggle = function (item) {
            var plugin = this;
            var options = $(plugin).data(pluginName);

            return function () {
                if ($(this).hasClass("fa-caret-right")) {
                    if (options.asyncLoad) {
                        $(this).parent().next("ul").remove();
                        $.ajax({
                            url: options.dataloadUrl,
                            type: "post",
                            data: JSON.stringify(item.data),
                            context: item,
                            cache: false,
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            beforeSend: function () {
                                $(this.element).find("> div > a").removeClass("fa-caret-right").addClass("fa-spinner").addClass("fa-spin");
                            },
                            success: function (response) {
                                if (!response.success) {
                                    if (response.redirectUri)
                                        window.location.href = response.redirectUri;
                                    if (response.message) {
                                    }
                                    return;
                                }
                                else if (response.data) {
                                    for (var i = 0; i < response.data.length; i++) {
                                        methods.createNode.apply($(plugin), [{ data: response.data[i], element: this.element, parentData: this.data }]);
                                    }
                                }

                                $(this.element).find("> ul").slideDown("normal");
                                if (options.nodeExpanded && $.isFunction(options.nodeExpanded)) {
                                    options.nodeExpanded(this.data);
                                }
                            },
                            error: function (xhr) {
                                var response = $.parseJSON(xhr.responseText);
                                if (response && response.message) {
                                }
                            },
                            complete: function (xhr) {
                                $(this.element).find("> div > a").removeClass("fa-spinner").removeClass("fa-spin").addClass("fa-caret-down");
                            }
                        });
                    }
                    else {
                        $(this).removeClass("fa-caret-right").addClass("fa-caret-down");
                        $(this).parent().next("ul").slideDown("normal");
                        if (options.nodeExpanded && $.isFunction(options.nodeExpanded)) {
                            options.nodeExpanded(item.data);
                        }
                    }

                } else {
                    $(this).removeClass("fa-caret-down").addClass("fa-caret-right");
                    $(this).parent().next("ul").slideUp("normal", function () {
                        if (options.asyncLoad) {
                            if (item.data[options.childrenField])
                                item.data[options.childrenField] = null;
                            $(this).remove();
                        }
                    });
                    if (options.nodeCollapsed && $.isFunction(options.nodeCollapsed)) {
                        options.nodeCollapsed(item.data);
                    }
                }
            }
        };

        var methods = {
            init: function (opt) {
                return $(this).each(function () {

                    var $treeview = $(this);
                    var options = createSetting.apply($treeview, [opt]);

                    $treeview.empty();
                    if ($.isArray(options.treeModel)) {
                        for (var i = 0; i < options.treeModel.length; i++) {
                            var root = options.treeModel[i];
                            if (options.asyncLoad)
                                methods.createNode.apply($treeview, [{ data: root, element: null, parentData: null }]);
                            else
                                recursion.apply($treeview, [{ data: root, element: null, parentData: null }]);
                        }
                    }
                    else if ($.isPlainObject(options.treeModel)) {
                        var root = options.treeModel;
                        if (options.asyncLoad)
                            methods.createNode.apply($treeview, [{ data: root, element: null, parentData: null }]);
                        else
                            recursion.apply($treeview, [{ data: root, element: null, parentData: null }]);
                    }
                });
            },
            destroy: function (opt) {
                return $(this).each(function () {
                    var $this = $(this);
                    $this.removeData(pluginName);
                });
            },

            createNode: function (item) {
                var plugin = this;
                var options = $(plugin).data(pluginName);
                var nodeData = item.data,
                    $parentNode = $(item.element),
                    parentNodeData = item.parentData;

                if (!nodeData)
                    return;

                var isRoot = ($parentNode == null || $parentNode.length <= 0);
                if (isRoot)
                    $parentNode = $(plugin);

                var $ul = $parentNode.find("> ul");
                if ($ul.length <= 0) {
                    $ul = $('<ul></ul>');
                    $ul.appendTo($parentNode);
                    if (!isRoot && !options.autoExpand)
                        $ul.hide();
                }
                if (options.asyncLoad) {
                    if (!$ul.is(":hidden") && parentNodeData) {
                        parentNodeData[options.childrenField] = parentNodeData[options.childrenField] || [];
                        parentNodeData[options.childrenField].push(nodeData);
                    }
                }
                var $treeIcon;
                if (!isRoot) {
                    $treeIcon = $parentNode.find("> div > a");
                    if ($treeIcon.length <= 0) {
                        var iconId = $ul.is(":hidden") ? "fa-caret-right" : "fa-caret-down";
                        $treeIcon = $('<a href="#" class="fa ' + iconId + '"></a>');
                        $treeIcon.prependTo($parentNode.find("> div"));

                        $treeIcon.click(nodeToggle.apply(plugin, [{ data: item.parentData, element: item.element }]));
                    }
                }

                var $node = $("<li></li>");
                $node.appendTo($ul);
                var $div = $("<div></div>");
                $div.appendTo($node);
                $treeIcon = null;
                if (nodeData.HasChild) {
                    var iconId = (options.asyncLoad || !options.autoExpand) ? "fa-caret-right" : "fa-caret-down";
                    $treeIcon = $('<a href="#" class="fa ' + iconId + '"></a>');
                    $treeIcon.appendTo($div);
                }

                var $span = $('<span><i class="fa"></i> <span>' + nodeData[options.displayField] + '</span></span>');
                $span.appendTo($div);
                if (options.selectedItem && nodeData[options.uniqueField] == options.selectedItem.data[options.uniqueField]) {
                    $span.addClass("actived");
                }
                if (nodeData.NodeType == 255) {
                    $span.find("> i").addClass("fa-th");
                }
                else if (nodeData.NodeType == 8) {
                    $span.find("> i").addClass(nodeData[options.iconField] || "fa-folder-o");
                }
                else if (nodeData.NodeType == 2) {
                    $span.find("> i").addClass(nodeData[options.iconField] || "fa-cog");
                }
                else if (nodeData.NodeType == 1) {
                    $span.find("> i").addClass(nodeData[options.iconField] || "fa-link");
                }
                var newitem = { data: nodeData, element: $node.get(0), parentData: parentNodeData };
                if ($treeIcon) {

                    $treeIcon.click(nodeToggle.apply(plugin, [newitem]));
                }

                $span.click((function (item) {
                    return function () {
                        $(plugin).find(".actived").removeClass("actived");
                        $(this).addClass("actived");
                        options.selectedItem = item;
                    }
                })(newitem));

                if (options.nodeRender)
                    options.nodeRender.apply(this, [newitem]);

                return $node;
            },
            deleteNode: function (item) {

                var options = $(this).data(pluginName);
                var nodeData = item.data,
                    $node = $(item.element),
                    parentNodeData = item.parentData;
                options.selectedItem = null;
                if (parentNodeData) {
                    var i = $.inArray(nodeData, parentNodeData[options.childrenField]);
                    if (i >= 0)
                        parentNodeData[options.childrenField].splice(i, 1);
                }
                var $ul = $node.parent();
                $node.remove();
                if ($ul.children().length <= 0) {
                    var $div = $ul.prev();
                    $div.find("> a").remove();
                    $ul.remove();
                }

            },
            updateNode: function (item) {

                var options = $(this).data(pluginName);
                var nodeData = item.data,
                    $node = $(item.element);

                var $div = $node.find("> div");
                var $span = $div.find("> span");
                var $icon = $span.find("> i");
                var $txt = $span.find("> span");
                $icon.attr("class", nodeData[options.iconField]);
                $txt.text(nodeData[options.displayField]);

            },

            selectedItem: function () {

                var plugin = this;
                var options = $(plugin).data(pluginName);
                var item = options.selectedItem;


                return item;
            }
        };

    })(jQuery);

    /********************* treeview end *********************/


    /********************* scroller begin *********************/
    (function ($) {

        var pluginName = "scroller";
        var defaults = {};
        $.fn[pluginName] = function () {
            var method = arguments[0];
            var func = methods[method];
            var args = arguments;
            if (func && $.isFunction(func)) {
                args = Array.prototype.slice.call(args, 1);
            } else if ($.isPlainObject(method) || !method) {
                func = methods.init;
            } else {
                $.error('方法名 "' + method + '" 不存在。');
                return this;
            }
            return func.apply(this, args);
        };

        //初始化设置
        var createSetting = function (opt) {
            opt = opt || {};

            var plugin = $(this);
            var options = plugin.data(pluginName);
            if ($.type(options) == 'undefined') {
                options = $.extend({}, defaults, opt);
            } else {
                options = $.extend({}, options, opt);
            }
            plugin.data(pluginName, options);
            return options;
        };

        var methods = {
            init: function (opt) {
                return $(this).each(function () {
                    var options = createSetting.apply(this, [opt]);

                    var $scroller = $('<div></div>');
                    $scroller.prop('class', $(this).attr('class'));
                    $scroller.addClass('scroller');
                    $(this).wrap($scroller);


                    var $scrollbar = $('<div class="scrollbar"></div>');
                    $(this).after($scrollbar);
                    var $thumb = $('<div class="scrollbar-thumb"></div>');
                    $thumb.appendTo($scrollbar);

                    $(this).css('height', 'inherit');
                    var showScrollbar = function () {
                        var totalHeight = 0;
                        $(this).children(":not(.scrollbar)").each(function () {
                            var height = $(this).outerHeight();
                            totalHeight += height;
                        });
                        console.log(totalHeight + ">" + $(this).innerHeight());
                        if (totalHeight > $(this).innerHeight())
                            $scrollbar.show();
                    };
                    $scroller.mousemove(debounce(showScrollbar));
                    $scroller.hover(showScrollbar, function () {
                        $scrollbar.hide();
                    });

                    $thumb.hover(function () {
                        $(this).css({ opacity: 1 });
                    }, function () {
                        $(this).css({ opacity: 0.6 });
                    });
                });
            },
            destroy: function (opt) {
                return $(this).each(function () {
                    var $this = $(this);
                    $this.removeData(pluginName);
                });
            },

        }

    })(jQuery);

    /********************* scroller end *********************/

    (function ($) {

        /********* ajax begin ***********/
        $.getsubmit = function (opt) {

            var defaults = {
                url: window.location.href,
                showProcessing: true,
                loadingText: "处理中，请稍候...",
                context: $,
                callback: null
            };
            var options = $.extend({}, defaults, opt);
            $.ajax({
                url: options.url,
                type: "get",
                dataType: "json",
                context: options.context,
                cache: false,
                beforeSend: function () { if (options.showProcessing) $(document.body).process('show', options.loadingText); },
                success: (function (callback) {
                    return function (response) {
                        if (response) {
                            if (response.message) {
                                $.alert(response.message);
                            }
                            if (!response.success) {
                                if (response.redirectUri)
                                    window.location.href = response.redirectUri;
                            }
                        }
                        if (callback && $.isFunction(callback))
                            callback.apply(this, [response]);
                    }
                })(options.callback),
                error: function (response) {
                    if (response && response.message) {
                        $.alert(response.message);
                    }
                },
                complete: function (xhr) {
                    if (options.showProcessing) $(document.body).process('hide');
                }
            });
        };

        $.postsubmit = function (opt) {
            var defaults = {
                url: window.location.href,
                showProcessing: true,
                postData: null,
                context: $,
                loadingText: "处理中，请稍候...",
                callback: null
            };
            var options = $.extend({}, defaults, opt);
            $.ajax({
                url: options.url,
                type: "post",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                context: options.context,
                cache: false,
                data: JSON.stringify(options.postData),
                beforeSend: function () { if (options.showProcessing) $(document.body).process('show', options.loadingText); },
                success: (function (callback) {
                    return function (response) {
                        if (response) {
                            if (response.message) {
                                $.alert(response.message);
                            }
                            if (!response.success) {
                                if (response.redirectUri)
                                    window.location.href = response.redirectUri;
                            }
                        }
                        if (callback && $.isFunction(callback))
                            callback.apply(this, [response]);
                    }
                })(options.callback),
                error: function (response) {
                    if (response && response.message) {
                        $.alert(response.message);
                    }
                },
                complete: function (xhr) {
                    if (options.showProcessing) $(document.body).process('hide');
                }
            });
        };

        /********* ajax end ***********/


        $.threadPool = function (opt) {
            var defaults = {
                url: window.location.href,
                retryTimes: 3,
                ignoreError: false,
                interval: 3000,
                pushData: null,
                success: null,
                error: null
            };

            var threadItems = [];

        };
        $.connect = function (opt) {
            var defaults = {
                url: window.location.href,
                retryTimes: 3,
                ignoreError: false,
                interval: 3000,
                pushData: null,
                success: null,
                error: null
            };

            var options = $.extend({}, defaults, opt);
            var canRetryTimes = options.retryTimes;

            function push() {
                setTimeout(function () {
                    $.ajax({
                        url: options.url,
                        type: "post",
                        cache: false,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: JSON.stringify(options.pushData),
                        success: function (response) {
                            if (options.success && $.isFunction(options.success))
                                options.success(response);
                            if (response.success) {
                                if (canRetryTimes < options.retryTimes)
                                    canRetryTimes = options.retryTimes;
                                push();
                            }
                            else {
                                if (options.ignoreError || canRetryTimes--)
                                    push();
                            }
                        },
                        error: function (response) {
                            if (options.error && $.isFunction(options.error))
                                options.error(response);
                            if (options.ignoreError || canRetryTimes--)
                                push();
                        }
                    });

                }, options.interval);
            }

            push();
        };
    })(jQuery);


})